var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
(function (factory) {
    if (typeof module === "object" && typeof module.exports === "object") {
        var v = factory(require, exports);
        if (v !== undefined) module.exports = v;
    }
    else if (typeof define === "function" && define.amd) {
        define(["require", "exports", "react", "components/common/component", "mobile/services/userData", "common", "components/common/base-component", "maishu-services-sdk", "maishu-ui-toolkit"], factory);
    }
})(function (require, exports) {
    "use strict";
    var MemberPage_1;
    Object.defineProperty(exports, "__esModule", { value: true });
    const React = require("react");
    const component_1 = require("components/common/component");
    const userData_1 = require("mobile/services/userData");
    const common_1 = require("common");
    const base_component_1 = require("components/common/base-component");
    const maishu_services_sdk_1 = require("maishu-services-sdk");
    const ui = require("maishu-ui-toolkit");
    let imageService = base_component_1.createService(maishu_services_sdk_1.ImageService);
    let MemberPage = MemberPage_1 = class MemberPage extends base_component_1.BaseComponent {
        constructor(props) {
            super(props);
            this.state = {
                balance: userData_1.userData.balance.value,
                score: userData_1.userData.score.value,
                userInfo: userData_1.userData.userInfo.value,
                sellsCenter: 'showToMember',
            };
            // this.state.balance = userData.balance.value;
            userData_1.userData.balance.add((value) => {
                // this.state.balance = value;
                // this.setState(this.state);
                this.setState({ balance: value });
            });
            // member.userInfo().then(userInfo => {
            //     this.state.userInfo = userInfo;
            //     this.setState(this.state);
            // });
            // this.state.userInfo = userData.userInfo.value;
        }
        componentDidMount() {
            common_1.subscribe(this, userData_1.userData.userInfo, (value) => {
                // this.state.userInfo = value;
                // this.setState(this.state);
                this.setState({ userInfo: value });
            });
        }
        render() {
            let { balance, userInfo, showLevel, sellsCenter, score } = this.state;
            let { bg, showBalance, showScore } = this.props;
            let bg_url = bg ? imageService.imageSource(bg) : MemberPage_1.default_bg;
            userInfo = userInfo || {};
            return (React.createElement("div", { className: "memberControl" },
                React.createElement("div", { className: "mobile-user-info text-center", style: { backgroundImage: `url(${bg_url})` } },
                    React.createElement("a", { href: "#user/userInfo" },
                        React.createElement("img", { src: userInfo.HeadImageUrl, className: "img-circle img-full", title: "\u4E0A\u4F20\u5934\u50CF", ref: (e) => e ?
                                ui.renderImage(e, {
                                    imageSize: { width: 100, height: 100 },
                                    imageText: "上传头像"
                                }) : null })),
                    React.createElement("div", { className: "nick-name" }, userInfo.NickName == null ? '未填写' : userInfo.NickName),
                    showBalance ?
                        React.createElement("div", { className: "balance text-right" },
                            React.createElement("span", null, "\u4F59\u989D"),
                            React.createElement("span", { className: "price" },
                                "\uFFE5",
                                (balance || 0).toFixed(2))) : null),
                React.createElement("div", { className: "order-bar" },
                    React.createElement("div", { className: "col-xs-3" },
                        React.createElement("button", { className: "btn-link", style: { color: 'black' }, onClick: () => this.app.forward("shopping/orderList") },
                            React.createElement("i", { className: "icon-list icon-3x" }),
                            React.createElement("div", { className: "name" }, "\u5168\u90E8\u8BA2\u5355"))),
                    React.createElement("div", { className: "col-xs-3 " },
                        React.createElement("a", { href: "#shopping/orderList?type=WaitingForPayment", style: { color: 'black' } },
                            React.createElement("i", { className: "icon-credit-card icon-3x" }),
                            React.createElement("div", { className: "name" }, "\u5F85\u4ED8\u6B3E"))),
                    React.createElement("div", { className: "col-xs-3" },
                        React.createElement("a", { href: "#shopping/orderList?type=Send", style: { color: 'black' } },
                            React.createElement("i", { className: "icon-truck icon-3x" }),
                            React.createElement("div", { className: "name" }, "\u5F85\u6536\u8D27"))),
                    React.createElement("div", { className: "col-xs-3" },
                        React.createElement("a", { href: "#shopping_evaluation", style: { color: 'black' } },
                            React.createElement("i", { className: "icon-star icon-3x" }),
                            React.createElement("div", { className: "name" }, "\u5F85\u8BC4\u4EF7"))),
                    React.createElement("div", { className: "clearfix" })),
                React.createElement("div", { className: "list-group" },
                    React.createElement("button", { className: "list-group-item", onClick: () => this.app.forward("user/receiptList") },
                        React.createElement("span", { className: "icon-chevron-right pull-right" }),
                        React.createElement("span", { className: "pull-right value", style: { display: 'none' } }),
                        React.createElement("strong", null, "\u6536\u8D27\u5730\u5740")),
                    React.createElement("a", { className: "list-group-item", href: "#user/favors" },
                        React.createElement("span", { className: "icon-chevron-right pull-right" }),
                        React.createElement("span", { className: "pull-right value", style: { display: 'none' } }),
                        React.createElement("strong", null, "\u6211\u7684\u6536\u85CF")),
                    React.createElement("a", { className: "list-group-item", href: "#user_coupon" },
                        React.createElement("span", { className: "icon-chevron-right pull-right" }),
                        React.createElement("span", { className: "pull-right value", style: { display: 'none' } }, "undefined"),
                        React.createElement("strong", null, "\u6211\u7684\u4F18\u60E0\u5238")),
                    showScore ?
                        React.createElement("a", { className: "list-group-item", href: "#user_scoreList" },
                            React.createElement("span", { className: "icon-chevron-right pull-right" }),
                            React.createElement("span", { className: "pull-right value price", style: { paddingRight: 8, display: score ? null : 'none' } }, score || 0),
                            React.createElement("strong", null, "\u6211\u7684\u79EF\u5206")) : null),
                sellsCenter ?
                    React.createElement("div", { className: "list-group" },
                        React.createElement("a", { className: "list-group-item" },
                            React.createElement("span", { className: "icon-chevron-right pull-right" }),
                            React.createElement("strong", null, "\u9500\u552E\u5458\u4E2D\u5FC3"))) : null,
                React.createElement("div", { className: "list-group" },
                    React.createElement("a", { className: "list-group-item", href: "#user/accountSecurity/index" },
                        React.createElement("span", { className: "icon-chevron-right pull-right" }),
                        React.createElement("span", { "data-bind": "text: value,visible:value", className: "pull-right value", style: { display: 'none' } }),
                        React.createElement("strong", null, "\u8D26\u6237\u5B89\u5168")),
                    React.createElement("button", { className: "list-group-item btn-link", onClick: () => null },
                        React.createElement("span", { className: "icon-chevron-right pull-right" }),
                        React.createElement("span", { className: "pull-right value", style: { display: 'none' } }),
                        React.createElement("strong", null, "\u9000\u51FA")))));
        }
    };
    MemberPage.default_bg = common_1.stationPath('components/member/images/bg_user.png');
    MemberPage.defaultProps = { bg: MemberPage_1.default_bg, showBalance: false, showScore: false };
    MemberPage = MemberPage_1 = __decorate([
        component_1.component()
    ], MemberPage);
    exports.MemberPage = MemberPage;
});
